plant = {

    Scene: function(options) {
        this.width = options.width;
        this.height = options.height;
        this.nodes = [];
        this.htmlNode = document.getElementById(options.htmlNodeId);
        if (this.htmlNode.getContext) {
            this.context = this.htmlNode.getContext('2d');
            this.htmlNode.width = options.width;
            this.htmlNode.height = options.height;
        }
    },

    primitives: Object =  {

        Rectangle: function(options) {
            this.width = options.width;
            this.height = options.height;
            this.color = options.color;
            this.type = 'rectangle';
            this.x = options.x;
            this.y = options.y;
        },

        Ellipse: function(options) {
            this.width = options.width;
            this.height = options.height;
            this.color = options.color;
            this.x = options.x;
            this.y = options.y;
            this.type = 'ellipse';
        },

    },
        

        
};

/////////////////////////////////////////////////////////////////////////////////////////


plant.Scene.prototype.update = function() {

    for(var i=0; i < this.nodes.length; i++) {

        var T = this.nodes[i];
        var ctx = this.context;
        ctx.fillStyle = T.color;

        switch(T.type) {

            case 'rectangle':
                ctx.fillRect(T.x, T.y, T.width, T.height);
            break;

            case 'ellipse':
                var kappa = .5522848;
                var ox = (T.width / 2) * kappa;
                var oy = (T.height / 2) * kappa;
                var xe = T.x + T.width;
                var ye = T.y + T.height;
                var xm = T.x + T.width / 2;
                var ym = T.y + T.height / 2;

                ctx.beginPath();
                ctx.moveTo(T.x, ym);
                ctx.bezierCurveTo(T.x, ym - oy, xm - ox, T.y, xm, T.y);
                ctx.bezierCurveTo(xm + ox, T.y, xe, ym - oy, xe, ym);
                ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
                ctx.bezierCurveTo(xm - ox, ye, T.x, ym + oy, T.x, ym);
                ctx.closePath();
                ctx.fill();
            break;

            default:
                /* nop */
            break;
        }
    }
}

plant.Scene.prototype.addChild = function(child) {
    this.nodes.push(child);
}

plant.Scene.prototype.fillBackground = function(color) {
    this.context.fillStyle = color;
    this.context.fillRect(0, 0, this.htmlNode.width, this.htmlNode.height);
}

